package aiku.numericalcontroloa.common.framework.swagger2;

import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import springfox.documentation.OperationNameGenerator;

import java.util.Map;

@Component
@Slf4j
public class NameGenerator implements OperationNameGenerator {
    private Map<String, Integer> generated = Maps.newHashMap();

    public NameGenerator() {
    }

    public String startingWith(String prefix) {
        if (this.generated.containsKey(prefix)) {
            this.generated.put(prefix, (Integer) this.generated.get(prefix) + 1);
            String nextUniqueOperationName = String.format("%s_%s", prefix, this.generated.get(prefix));
            return nextUniqueOperationName;
        } else {
            this.generated.put(prefix, 0);
            return prefix;
        }
    }
}

